var qrConfig = {
    icon:'http://cms.sellerpartner.cn/Poster/GetUrlQrCode?width=200&height=200',
    width:'50px',
    height:'80px',
    top:'160px',
    right:'5%', 
    text:'',
    textVisible:true
};
if (document.currentScript) {
    qrConfig.width = document.currentScript.getAttribute("w")||qrConfig.width;
    qrConfig.height = document.currentScript.getAttribute("h")||qrConfig.height;
    qrConfig.top = document.currentScript.getAttribute("t")||qrConfig.top ;
    qrConfig.right = document.currentScript.getAttribute("r")||qrConfig.right;
    qrConfig.icon = document.currentScript.getAttribute("icon")||qrConfig.icon; 
    qrConfig.text = document.currentScript.getAttribute("text")||'';
    qrConfig.textVisible = document.currentScript.getAttribute("textvisible")!=="false";
}

var _qrCode_initial =function()
{ 
    var qr_box  = document.createElement('div');
     
    qr_box.style.position="fixed";
    qr_box.style.display = "flex";
    qr_box.style.flexFlow = "column";
    qr_box.style.justifyContent = "center";
    qr_box.style.alignItems = "center";
    qr_box.style.width = qrConfig.width;
    qr_box.style.height = qrConfig.height;
    qr_box.style.top = qrConfig.top;
    qr_box.style.right = qrConfig.right;
    qr_box.style.lineHeight = "30px";
    qr_box.style.fontSize = "80%";
    qr_box.style.cursor = "pointer";
    qr_box.style.backgroundColor = "transparent"; 

    var qr_code  = document.createElement('div');
    qr_code.style.display = "block";
    qr_code.style.width = "50px";
    qr_code.style.height= "50px";
    qr_code.style.border = "1px #a8a7a7 solid";
    qr_code.style.borderRadius = "5px";
    qr_code.style.backgroundImage = "url(" + qrConfig.icon + ")";
    qr_code.style.backgroundPosition = "center"; 
    qr_code.style.backgroundRepeat = "no-repeat"; 
    qr_code.style.backgroundSize = "75%";
    qr_code.style.backgroundColor = "transparent"; 
     
    var btn = document.createElement('label');
    btn.innerHTML="关闭";
    btn.style.fontSize = "80%";
    btn.style.lineHeight = "30px";
    btn.style.cursor = "pointer";
    btn.style.display = "none";
    btn.style.float = "right";
    btn.style.color = "blue";  
    btn.style.position ="absolute";
    btn.style.top = "0px";
    btn.style.right = "5px";
    
    var txt = document.createElement('label');
    txt.innerHTML = "扫码手机上打开该网页";
    txt.style.color = "#524c4c9e";
    txt.style.fontSize= "80%";
    txt.style.display = "none";
    txt.style.position = "absolute";
    txt.style.bottom = "2px";
    txt.style.width = "100%";
    txt.style.textAlign = "center";

    qr_box.appendChild(btn);
    qr_box.appendChild(qr_code);

    if(qrConfig.textVisible)
        {
            var label = document.createElement('label');
            label.innerHTML = qrConfig.text;
            label.style.color = "#524c4c9e";
            label.style.fontSize= "80%"; 
            label.style.bottom = "0px";
            label.style.width = "100%";
            label.style.textAlign = "center";
         
            qr_box.appendChild(label);
        }

   
    qr_box.appendChild(txt);
    document.body.appendChild(qr_box);
    var closeQr = function()
    {
         qr_box.style.zIndex = "";
        qr_box.style.width = qrConfig.width||"50px";
        qr_box.style.height = qrConfig.height||"80px";
        qr_box.style.borderRadius = "5px"; 
        qr_box.style.backgroundColor = "transparent";
        qr_box.style.cursor = "pointer";
        qr_box.style.border = "";
        qr_box.style.boxShadow= "";

        qr_code.style.width = "50px";
        qr_code.style.height= "50px";
        qr_code.style.border = "1px #a8a7a7 solid";
        txt.style.display = "none";
        label.style.display = "";
        btn.style.display ="none";

        //删除事件
        document.body.removeEventListener("click" , closeQr);
    };
    var showQr = function()
    {
        qr_box.style.zIndex = 998;
        qr_box.style.width = "300px";
        qr_box.style.height = "300px"; 
        qr_box.style.borderRadius = "10px";
        qr_box.style.backgroundColor = "#fff";
        qr_box.style.cursor = "default";
        qr_box.style.boxShadow = "10px 11px 8px 2px #524c4c9e";
        qr_box.style.border = "1px #a8a7a7 solid";

        qr_code.style.width = "100%";
        qr_code.style.height= "95%";
        qr_code.style.border = "";
        txt.style.display = "";
        label.style.display = "none";
        btn.style.display="";

        //追加事件
        document.body.addEventListener("click" , closeQr);

    };
   
    qr_box.onclick = function(e)
    { 
        if(qr_box.style.width == "300px")
        {
            closeQr();
        }
        else
        {
            showQr();
        }
        
        e.stopPropagation();
    }
};
window.addEventListener('load',_qrCode_initial);